<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/10/18
  Time: 9:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-table.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/jquery.validate.js"></script>
    <script src="js/jquery.form.js"></script>
    <script src="js/messages_zh.js"></script>
</head>
<body>
<!--头部-->
<div class="modal-header">
    <button class="close" data-dismiss="modal">&times;</button>
    <h3>添加角色</h3>
</div>
<form id="addrole" class="form-horizontal">
    <!--身体-->
    <div class="modal-body">

        <div class="form-group">
            <label class="control-label col-md-2" for="name">角色名称:</label>
            <div class="col-md-10">
                <input type="text" id="name" name="name" class="form-control" placeholder="请输入角色名称" required>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="code">角色编号:</label>
            <div class="col-md-10">
                <input type="text" id="code" name="code" placeholder="请输入角色编号" class="form-control" required>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="descn">角色说明:</label>
            <div class="col-md-10">
                    <input type="text" id="descn" name="descn" placeholder="请输入角色说明" class="form-control" required>
            </div>
        </div>
    </div>
    <!--底部-->
    <div class="modal-footer">
        <div>
            <input type="submit" value="添加角色" class="btn btn-info col-md-2 col-md-offset-2">
            <input type="reset" value="重置" class="btn btn-success col-md-2 col-md-offset-3">
            <input type="button" value="关闭" class="btn btn-danger col-md-2 col-md-offset-1">
        </div>
    </div>
</form>

<script>
    $("#addrole").validate({
        messages:{
            name:"角色名称不能为空",
            code:"角色编号不能为空",
            descn:"角色说明不能为空"
        },
        submitHandler:function () {
            $("#addrole").ajaxSubmit({
                url:"addroles.action",
                type:"post",
                dataType:"json",
                success:function (data) {
                    alert(data.msg)
                    if(data.code==1){
                        location.href="roles.jsp";
                    }else {
                        location.href="addrole.jsp";
                    }
                }
            })
        }
    })
</script>
</body>
</html>
